package blackitheima1.ClassTest;

import blackitheima1.Domain.Student;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

//反射--获取Method成员方法
public class MyClass4 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InstantiationException, InvocationTargetException {
        //创建Class对象
        Class aClass = Class.forName("blackitheima1.Domain.Student");
        //调用成员方法
        Method method = aClass.getDeclaredMethod("sleep", String.class);
        //暴力反射
        method.setAccessible(true);

        //创建对象
        Student stu = (Student) aClass.newInstance();
        //调用方法
        Object o = method.invoke(stu, "装饰");
        System.out.println(o);
    }
}
